package com.easybuilder.common.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Set;

@Data
@NoArgsConstructor
public class DynamicEntity extends JSONObject {

    //重写put方法，满足链式编程写法
    @Override
    public DynamicEntity put(String fieldName, Object value) {
        super.put(fieldName, value);
        return this;
    }

    public Criteria createCriteria() {
        return new Criteria();
    }


    static class Criteria {

        private StringBuilder whereSql;

        public void andEquals(String fieldName, Object value) {
            whereSql.append(" and ").append(fieldName).append(" = '").append(value).append("'");
        }
    }

    @Override
    public String toString() {
        return this.toJSONString();
    }

}
